package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.GreTreePatrolLogDao;
import cn.topevery.garden.entity.po.GreTreePatrolLog;
import cn.topevery.garden.entity.query.GreTreePatrolLogQuery;
import cn.topevery.garden.entity.vo.GreTreePatrolLogVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 巡查记录表
 *
 * @author code-generate
 * @date 2022-02-27
 */
@Repository
public class GreTreePatrolLogDaoImpl extends BaseDaoImpl<GreTreePatrolLog> implements GreTreePatrolLogDao {
    @Override
    public <P extends DbCsp> List<GreTreePatrolLog> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<GreTreePatrolLogVO> listPage(GreTreePatrolLogQuery query) {
        String table = "t_gre_tree_patrol_log tgtpl";

        String columns = "tgtpl.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tgtpl.c_id desc");
        sqlQueryMate
                .where(true, "tgtpl.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getCode()), "tgtpl.c_code",ScriptConditionEnum.Like, query.getCode())
                .where(StringUtils.isNotBlank(query.beginDate), "tgtpl.c_dig_time",ScriptConditionEnum.GreaterThanEq, query.beginDate)
                .where(StringUtils.isNotBlank(query.endDate), "tgtpl.c_dig_time",ScriptConditionEnum.LessThanEq, query.endDate)
                .where(StringUtils.isNotBlank(query.getUserId()), "tgtpl.c_user_id",ScriptConditionEnum.Eq, query.getUserId())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, GreTreePatrolLogVO.class);
    }

    @Override
    public GreTreePatrolLog getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
